package com.kuang.demo.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuang.demo.bo.gh.CreateKeyWordBO;
import com.kuang.demo.mapper.KeyWordMapper;
import com.kuang.demo.pojo.KeyWordPOJO;
import com.kuang.demo.vo.CreateKeyWordVO;
import com.kuang.demo.vo.QueryIssueVO;
import com.kuang.demo.vo.QueryKeyWordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 郭浩 on 2020/11/3 15:34
 */
@Service
public class KeyWordServiceImpl implements KeyWordService{
    @Autowired
    KeyWordMapper keyWordMapper;
    @Override
    public Map<String, Object> queryKeyWordList(Integer page, Integer limit, String keyword, String url, String sort, String order) {
        PageHelper.startPage(page,limit);
        List<QueryKeyWordVO.ItemsBean> itemsBeans = keyWordMapper.queryKeyWordList(keyword,url,sort,order);
        PageInfo<QueryKeyWordVO.ItemsBean> itemsBeanPageInfo = new PageInfo<>(itemsBeans);
        Long i = itemsBeanPageInfo.getTotal();
        int total = i.intValue();
        Map<String,Object> issueInfo = new HashMap();
        issueInfo.put("issueList",itemsBeans);
        issueInfo.put("total",total);
        return issueInfo;
    }

    @Override
    public CreateKeyWordVO createKetWord(CreateKeyWordBO createKeyWordBO) {
        keyWordMapper.createKeyWord(createKeyWordBO);
        return keyWordMapper.queryKeyWordBy(createKeyWordBO.getId());
    }

    @Override
    public KeyWordPOJO updateKeyWord(KeyWordPOJO keyWordPOJO) {
        keyWordMapper.updateKeyWordById(keyWordPOJO);
        KeyWordPOJO keyWordPOJO1 = keyWordMapper.queryKeyWordAllById(keyWordPOJO.getId());

        return keyWordPOJO1;
    }

    @Override
    public void deleteKeyWord(KeyWordPOJO keyWordPOJO) {
        keyWordMapper.deleteKeyWord(keyWordPOJO.getId());
    }
}
